package cn.stylefeng.guns.modular.robot.cmd.impl;

import cn.stylefeng.guns.modular.robot.cmd.abs.AbstractCmd;
import cn.stylefeng.guns.modular.robot.entity.Group;
import cn.stylefeng.guns.modular.robot.service.GroupService;
import cn.stylefeng.guns.modular.robot.utils.RobotUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.meta.api.objects.Update;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Objects;

@Slf4j
@Service
@Transactional
public class CmdExtract extends AbstractCmd {

    @Resource
    private GroupService groupService;

    @Override
    public void exec(Update update, TelegramLongPollingBot bot) {
        String text = update.getMessage().getText();
        Long chatId = update.getMessage().getChatId();
        Group group = groupService.getGroupByTgGroupId(chatId);
        if (Objects.isNull(group)) {
            return;
        }
        group.setExtract(new BigDecimal(text.replace("设置单笔", "").trim()));
        groupService.updateById(group);
        RobotUtils.sendText(chatId, "本群单笔已修改为：" + group.getExtract(), bot);
    }

    @Override
    public String getCmdName() {
        return "设置单笔";
    }

    @Override
    public String getDescribe() {
        return "设置单笔                    设置群单笔，如：设置单笔1\n";
    }
}
